package cn.txauction.business.service.impl;


import java.util.Hashtable;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.txauction.business.service.ICommonService;
import cn.txauction.business.service.base.BaseService;
import cn.txauction.modal.TblMaster;

/**
 * 
 * @author 胡
 *
 */
@Service("commonService")
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public class CommonServiceImpl extends BaseService implements
ICommonService {

	public Hashtable<Short, Hashtable<Short,String>> getAppDicts() {
		// TODO Auto-generated method stub
		Hashtable<Short, Hashtable<Short,String>> dicts = null;
		Hashtable<Short, String> dictItem = null;
		List<TblMaster> masters = masterDao.findAll();
		if(masters.size() > 0){
			//add the first dict item
			dicts = new Hashtable<Short, Hashtable<Short,String>>();
			dictItem = new Hashtable<Short, String>();
			dictItem.put(masters.get(0).getFdType1(), masters.get(0).getFdContent());
			dicts.put(masters.get(0).getFdDiccode(), dictItem);
			
			//add others
			for(int i=1; i<masters.size(); i++){
				TblMaster master = masters.get(i);
				//if exists
				if(!dicts.containsKey(master.getFdDiccode())){
					dictItem = new Hashtable<Short, String>();
					dictItem.put(master.getFdType1(), master.getFdContent());
					dicts.put(master.getFdDiccode(), dictItem);	
				}else{
					if(!dicts.get(master.getFdDiccode()).containsKey(master.getFdType1())){
						dicts.get(master.getFdDiccode()).put(master.getFdType1(), master.getFdContent());	
					}
				}
				
			}
		}
		return dicts;
	}
	
}
